{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 合数阶双线性群"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 初始化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from Util import a1_param_generator\n",
    "from charm.toolbox.pairinggroup import PairingGroup, G1, ZR, pair as e\n",
    "\n",
    "a1_path = '../pbc.conf.d/a1.properties'\n",
    "primes = a1_param_generator(60, 3, a1_path)\n",
    "group = PairingGroup(a1_path, param_file = True)\n",
    "# group = PairingGroup('SS1024')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 生成元"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "g = group.random(G1)\n",
    "print(g)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 子群元素选取\n",
    "假设合数阶双线性群$G$的阶$ p=p_0p_1\\cdots p_{n-1} $，其中$p_i$为第$i$个子群的阶，那么第$i$个子群的生成元为：\n",
    "$$\n",
    "g_i=g^{\\prod_{j=0,j\\ne i}^{n-1}{p_j}}=g^{p_0p_1\\cdots p_{i-1}p_{i+1}\\cdots p_{n-1}}=g^{p/p_i}\n",
    "$$\n",
    "$g$为$G$的生成元"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "g0 = g ** (group.order() // primes[0])\n",
    "g1 = g ** (group.order() // primes[1])\n",
    "g2 = g ** (group.order() // primes[2])\n",
    "\n",
    "print(f'h0: {g0}\\nh1: {g1}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 正交性\n",
    "$$\n",
    "e\\left( g_i,g_j \\right) =1, i\\ne j\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "one = e(g2, g0)\n",
    "print(one)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  },
  "vscode": {
   "interpreter": {
    "hash": "e5030792b3492f6b12d94f1f48beca3d8e59ec05fd59d0aaaa48e684281ed297"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
